﻿using System;

namespace HomeWork4
{
    class Program
    {
        public abstract class graph
        {
            public double[] edge;
            public double angle;
            public abstract bool Legalization();
        }
   
        public class triangle: graph
        {
            public  new double[] edge = new double[3];
            public  new double angle;
            public triangle(double[] edge)
            {
                this.edge = edge;
                this.angle = (edge[0] * edge[0] + edge[1] * edge[1] - edge[2] * edge[2]) / (2 * edge[0] * edge[1]);
            }
            public override bool Legalization()
            {
                if (edge[0] + edge[1] > edge[2] && edge[0] + edge[2] > edge[1] && edge[1] + edge[2] > edge[0])
                    return true;
                else
                    return false;                 
            }

            public double Area()
            {
                if (this.Legalization())
                    return (edge[0] *System.Math.Sqrt(1 - angle * angle) * edge[1] / 2);
                else
                    return -1;
            }
        }

        public class rectangle : graph
        {
            public new double[] edge = new double[2];
            public new double angle;
            public rectangle(double[] edge, double angle)
            {
                this.edge = edge;
                this.angle = angle;
            }
            public override bool Legalization()
            {
                if (angle == 90)
                    return true;
                else
                    return false;
            }

            public double Area()
            {
                if (this.Legalization())
                    return (edge[0] * edge[1]);
                else
                    return -1;
            }
        }
        static void Main(string[] args)
        {
            double[] edge_1 = { 3, 2, 4 };
            double[] edge_2 = { 3, 1, 2 };
            double[] edge_3 = { 5, 5 };
            double angle_3 = 90;
            triangle tri = new triangle(edge_1);
            triangle tri_1 = new triangle(edge_2);
            rectangle rec = new rectangle(edge_3, angle_3);
            Console.WriteLine("第一个三角形是否合法：" + tri.Legalization().ToString());
            Console.WriteLine("第一个三角形的面积：" + tri.Area().ToString());
            Console.WriteLine("第二个三角形是否合法：" + tri_1.Legalization().ToString());
            Console.WriteLine("第二个三角形的面积：" + tri_1.Area().ToString());
            Console.WriteLine("矩形是否合法：" + rec.Legalization().ToString());
            Console.WriteLine("矩形的面积：" + rec.Area().ToString());
        }
    }
}
